<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
	
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="../css/app.css" />
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
		<script src="../js/mui.min.js"></script>		
		<script src="../js/mui.picker.min.js"></script>
		<script src="../js/jquery-1.8.0.min.js"></script>
		<style>
			.file{position: absolute;top: 0rem;right:0.1rem ;z-index: 1;opacity: 0;}
			.kong{background: #efeff4;}
			input{font-size: 14px!important;}
			.mui-btn-blue{background: #ff7e00!important;border: none!important;}
			.diqu-div span{font-size: 14px;color: #323232;}
			.diqu-div{text-align: center;padding: 5px 0px;color:#ff7e00;}
		    .diqu-container{position: relative;}
		    .diqu-ul{position: absolute;top: 0px;left: 0px;width: 100%;padding: 5px;}
		    .diqu-ul li{margin: 5px;padding:0px 10px;color: #323232;font-size: 14px;height: 30px;line-height: 30px;border-bottom: 1px dashed #ccc;overflow: hidden;}
		    .city,.town{display: none;}
		    .diqu-ul li span:nth-of-type(2){float: right;font-size: 16px;color: #666;}
		    .quyu{display: none;}
		    .changep-form p span{width: 30%;}
		    .changep-form p input{padding-left: 0px;}
		    .ch-ph-btn{margin: 3.5rem auto;}
		    
		</style>
	</head>
	<body style="background: #FFFFFF;">
		<div class="mui-bar mui-bar-nav ding-bar" style="position: fixed;top: 0px;width: 100%;left: 0px;">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title" id="tt">发布互助</h1>
		</div>
		<div style="height: 44px;"></div>
		<div class="mui-content" style="background: #FFFFFF;">
		    <form class="changep-form" style="background: #fff;">
		    	<p><span><b style="color: red;">*</b>互助标题：</span><input type="text" name="title" id="title" placeholder="请输入互助标题"></p>
		    	<p><span><b style="color: red;">*</b>开始时间：</span>
		    		<input type="text" name="addtime" id="addtime"  class="inputs" data-options='{}' readonly placeholder="请选择开始时间"/>
		    	</p>
		    	<p><span><b style="color: red;">*</b>结束时间：</span>
		    		<input type="text" name="endtime" id="endtime" class="inputs" data-options='{}' readonly placeholder="请选择结束时间"/>
		    	</p>
		    	<p><span>互助薪酬：</span>
		    		<input type="number" name="price"id="price"  placeholder="请输入互助薪酬">
		    	</p>
		    	<p>
		    		<span><b style="color: red;">*</b>联&nbsp;系&nbsp;人：</span>
		    		<input type="text" name="linkname" id="linkname" placeholder="请输入联系人">
		    	</p>
		    	<p>
		    		<span><b style="color: red;">*</b>联系电话：</span>
		    		<input type="text" name="linkphone" id="linkphone" placeholder="请输入联系电话">
		    	</p>
		    	<p style="border-bottom: none;">
		    		<span><b style="color: red;">*</b>互助内容：</span>
		    		<textarea style="background: #efeff4;margin-top: 10px;padding: 5px;font-size: 14px;" name="content" id="content" placeholder="请输入互助内容" ></textarea>	
		    	</p>
		        <div style="padding: 2px 0px;">
		        	 <button class="ch-ph-btn" type="button" style="font-weight: bold;letter-spacing: 2px;height: 35px;">确认发布</button>
		        </div>
		        
		    </form>
		</div>
		<script src="../js/common.js"></script>
		<script src="../js/session.js"></script>
		<script type="text/javascript">	
			(function($) {
				$.init();
				var result = $('#result')[0];
				var btns = $('.inputs');
			
				btns.each(function(i, btn) {
					btn.addEventListener('tap', function() {
						var _self = this;
						if(_self.picker) {
							_self.picker.show(function (rs) {
								result.innerText = '选择结果: ' + rs.text;
								_self.picker.dispose();
								_self.picker = null;
							});
						} else {
							var optionsJson = this.getAttribute('data-options') || '{}';
							var options = JSON.parse(optionsJson);
							var id = this.getAttribute('id');
							/*
							 * 首次显示时实例化组件
							 * 示例为了简洁，将 options 放在了按钮的 dom 上
							 * 也可以直接通过代码声明 optinos 用于实例化 DtPicker
							 */
							_self.picker = new $.DtPicker(options);
							_self.picker.show(function(rs) {
								_self.value=rs.text;					
								_self.picker.dispose();
								_self.picker = null;
							});
						}
						
					}, false);
				});
			})(mui);

		</script>
		<script>
			var id =getQueryString("id");
			if(id!=null&&id!=""){
				$("#tt").html("修改互助")
				$(".ch-ph-btn").html("确认修改")
			}else{
				$("#tt").html("发布互助")
				$(".ch-ph-btn").html("确认发布")
			}
			$(function(){
				//读取上次填写的信息
				if(id){
					var data={};
					data.id=id;
					$.post(net+"/public/index.php?s=api/index/community_mess/",data,function(data){
		               if(data.code==200){
			               $("#title").val(data.result.title)
			               $("#addtime").val(data.result.addtime)
			               $("#endtime").val(data.result.endtime)
			               $("#linkname").val(data.result.linkname)
			               $("#linkphone").val(data.result.linkphone)
			               $("#price").val(data.result.price)
			               $("#content").val(data.result.content)   
		               }
				   },'json')
				}
			})
			$.fn.serializeObject = function() {  
		        var o = {};  
		        var a = this.serializeArray();  
		        $.each(a, function() {  
		            if (o[this.name]) {  
		                if (!o[this.name].push) {  
		                    o[this.name] = [ o[this.name] ];  
		                }  
		                o[this.name].push(this.value || '');  
		            } else {  
		                o[this.name] = this.value || '';  
		            }  
		        });  
		        return o;  
		    }
			var userid= getCookie("userid");
			if(!userid){
				alert("您还没有登录，请先登录");
				location.href="login.html"
			}
		    mui("body").on("tap",".ch-ph-btn",function(){	
		    	var $phone =/^1[0-9]{10,10}$/;
		    	var data = $(".changep-form").serializeObject();
		    	console.log(data)
		    	if(data.title==""||data.title==null){
		    		alert("请填写互助标题")
		    		return false;
		    	}
		    	if(data.addtime==""||data.addtime==null){
		    		alert("请选择开始时间")
		    		return false;
		    	}
		    	if(data.endtime==""||data.endtime==null){
		    		alert("请选择结束时间")
		    		return false;
		    	}
	    		var data1 = new Date(data.addtime);//当前时间
	    		var $date = new Date(data.endtime);//截至日期
	    		if($date.getTime()<data1.getTime()){
	    			alert("结束时间不能早于开始时间");
	    		    return false;
	    		}	
//		    	if(data.price==""||data.price==null){
//		    		alert("请填写互助薪酬")
//		    		return false;
//		    	}
		    	if(data.linkname==""||data.linkname==null){
		    		alert("请填写联系人")
		    		return false;
		    	}
		    	if(data.linkphone==""||data.linkphone==null){
		    		alert("请填写联系人电话")
		    		return false;
		    	}else if(!$phone.test(data.linkphone)){
		    		alert("请填写正确的电话号码")
		    		return false;
		    	}
		    	if(id){
		    		data.id=id;
		    	}
		    	data.member_id=userid;
		    	$.post(net+"/public/index.php?s=api/index/add_community",data,function(data){
	               if(data.code==200){
	               	    if(id!=null&&id!=""){
	               	   	    alert("修改成功")
	               	    }else{
	               	    	alert("发布成功")
	               	    }
		               	mui.back();
	               }
			   },'json'
			);
		    })
		</script>
	</body>

</html>